package com.chinacoal.hr.levelimpl.controller;

import com.chinacoal.hr.levelapi.client.OrganizationClient;
import com.chinacoal.hr.levelapi.client.response.Result;
import com.chinacoal.hr.levelapi.client.response.ResultGenerator;
import com.chinacoal.hr.levelapi.entity.Organization;
import com.chinacoal.hr.levelimpl.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: YunTao.Li
 * @create: 2019-11-29 22:16
 * @description:
 **/
@RestController
public class OrganizationController implements OrganizationClient{

    @Autowired
    private OrganizationService organizationService;

    /**
     * 获取机构或者部门
     *
     * @param parentOrgId :
     * @param isdept      : 是否是部门1是0否
     * @return : com.chinacoal.hr.levelapi.response.Result
     * @author : YunTao.Li
     * @date : 2019/12/3 2019/12/3
     */
    public Result orgList(String parentOrgId,
                          String isdept) {
        List<Organization> organizationList = null;
        try {
            if (("1").equals(isdept)) {
                organizationList = this.organizationService.getAbsoluteDepartments(parentOrgId);
            } else {
                organizationList = this.organizationService.getAbsoluteOrganizations(parentOrgId);
            }

        } catch (Throwable e) {
            e.printStackTrace();
            return ResultGenerator.genFailedResult(e.getMessage());
        }
        return ResultGenerator.genOkResult(organizationList);
    }
}
